<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Register a callback function to be called when events are posted</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.ibase-service-detach.html">ibase_service_detach</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ibase-trans.html">ibase_trans</a></div>
 <div class="up"><a href="ref.ibase.html">Firebird/InterBase 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.ibase-set-event-handler" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ibase_set_event_handler</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">ibase_set_event_handler</span> &mdash; <span class="dc-title">Register a callback function to be called when events are posted</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.ibase-set-event-handler-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>ibase_set_event_handler</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$event_handler</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$event_name1</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$event_name2</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$...</code></span>
  ]] )</div>

  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>ibase_set_event_handler</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span>
   , <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$event_handler</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$event_name1</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$event_name2</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$...</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   This function registers a PHP user function as event handler for the
   specified events. 
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ibase-set-event-handler-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">event_handler</code></em></dt>

     <dd>

      <p class="para">
       The callback is called with the event name and the link resource as
       arguments whenever one of the specified events is posted by the
       database.
      </p>
      <p class="para">
       The callback must return <strong><code>FALSE</code></strong> if the event handler should be
       canceled. Any other return value is ignored. This function accepts up
       to 15 event arguments.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">event_name1</code></em></dt>

     <dd>

      <p class="para">
       An event name.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">event_name2</code></em></dt>

     <dd>

      <p class="para">
       At most 15 events allowed.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ibase-set-event-handler-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The return value is an event resource. This resource can be used to free
   the event handler using <span class="function"><a href="function.ibase-free-event-handler.html" class="function">ibase_free_event_handler()</a></span>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ibase-set-event-handler-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1087">
    <p><strong>Example #1 <span class="function"><strong>ibase_set_event_handler()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">event_handler</span><span style="color: #007700">(</span><span style="color: #0000BB">$event_name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$event_name&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #DD0000">"NEW&nbsp;ORDER"</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;process&nbsp;new&nbsp;order<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ibase_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UPDATE&nbsp;orders&nbsp;SET&nbsp;status='handled'"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;if&nbsp;(</span><span style="color: #0000BB">$event_name&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #DD0000">"DB_SHUTDOWN"</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;free&nbsp;event&nbsp;handler<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">return&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">ibase_set_event_handler</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"event_handler"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"NEW_ORDER"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DB_SHUTDOWN"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ibase-set-event-handler-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.ibase-free-event-handler.html" class="function" rel="rdfs-seeAlso">ibase_free_event_handler()</a> - Cancels a registered event handler</span></li>
    <li class="member"><span class="function"><a href="function.ibase-wait-event.html" class="function" rel="rdfs-seeAlso">ibase_wait_event()</a> - Wait for an event to be posted by the database</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.ibase-service-detach.html">ibase_service_detach</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ibase-trans.html">ibase_trans</a></div>
 <div class="up"><a href="ref.ibase.html">Firebird/InterBase 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
